<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<title>管理平台</title>
<jsp:include page="../../include/header.jsp"></jsp:include>
<link
	href='${BASE_PATH}/static/plugins/jquery-treetable/css/jquery.treetable.css'
	media='all' rel='stylesheet' type='text/css' />
</head>
<body>
	<div id="wrapper"  class="row">
		
				<div class="col-lg-12">
				
					<h1 class="page-header">秒杀活动列表</h1>
						<label class="search-label">活动名称:</label> <input type="text"
						id="stitle" value="" class="form-control search-input width200"
						maxlength="21" placeholder="请输入活动名称">
					<button class="btn btn-success search-btn" onclick="query();">确定</button>
					<button class="btn btn-success search-btn" onclick="reset();">重置</button>
					<div class="pull-right">
						<button type="button"
							onclick="javascript:window.location.reload()"
							class="btn btn-success  btn-refresh pull-right margin-lr">
							<span class="fa fa-refresh fa-lg"></span>
						</button>
						
						<button type="button" class="btn btn-success pull-right margin-lr" onclick="toAdd()">
								<span class="fa fa-plus"></span> 添加活动
							</button>
						<div class=" btn pull-right margin-lr ">
							<%-- <a href="${BASE_PATH}/spike/time/index">秒杀时间段列表</a> --%>
						</div>
					</div>
				</div>

				<div class="col-lg-12 title-top">
					<div class="row">
						<div class="col-lg-6">
							<div class="text-muted single-line-text pull-left">
								共 <font color="#428bca" id="dataCount">0</font> 条记录
								
							</div>
						</div>
						<!-- <div class="col-lg-6"> -->
						
					</div>
					<div class="table-responsive">
						<table id="dataTable" class="table table-striped table-hover">
							<thead>
								<tr>
									<th>编号</th>
									<th>活动标题</th>
									<th>活动状态</th>
									<th>开始时间</th>
									<th>结束时间</th>
									<th>上线/下架</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="dataList"></tbody>
						</table>
					</div>
						<div class="col-lg-12">
							<ul id="dataPagination" class="pagination-sm pull-right"></ul>
						</div>
					</div>
		
	</div>
	<jsp:include page="../../include/javascripts.jsp"></jsp:include>
	<script type="text/html" id="datatpl">
	{{each list as item}}
<tr id="item{{item.id}}" data-id="{{item.id}}">
		<td>{{item.id}}</td>
		<td>{{item.active_title}}</td>
		<td>{{item.active_state}}</td>
		<td>{{item.start}}</td>
		<td>{{item.stop}}</td>
		<td>{{item.publish | flagTransform:1,'上架',0,'下架' }}</td>		
		<td><button type="button" class="btn btn-sm btn-primary btn-simple" onclick="toSet('{{item.id}}')"title="设置商品"><span class="fa fa-link fa-lg"></span></button><button type="button" class="btn btn-sm btn-primary btn-simple" onclick="toEdit('{{item.id}}')" title="编辑"><span class="fa fa-edit fa-lg"></span></button><button type="button" class="btn btn-sm btn-danger btn-simple" onclick="toDelete('{{item.id}}')" title="删除"><span class="fa fa-remove fa-lg"></span></button></td>
	</tr>
	{{/each}}
</script>
	<script type="text/javascript">
		var dataPaginator;
		$(query);
		function query() {
			var params = {
				pageSize : 10,
				title : $("#stitle").val()
			};
			if(dataPaginator) {
				dataPaginator.destroy();
			}
			dataPaginator = Kit.pagination("#dataPagination","${BASE_PATH}/spike/list/page", params, function(result){
						//设置显示最新的数据数量
						$("#dataCount").html(result.object.totalRow);
						//根据模板渲染数据并填充
						$("#dataList").empty().append(template("datatpl", result.object));
					});

		}
		function reset() {
			$("#stitle").val("");
		}

		var addDialog;
		function toAdd() {
			addDialog = Kit.dialog("添加活动", "${BASE_PATH}/spike/list/toAdd")
					.open();
		}
		function toDelete(id) {
			Kit.confirm("提示", "您确定要删除这条数据吗？", function(){$.post("${BASE_PATH}/spike/list/doDelete/"+id, function(result) {
					$("#item".id).remove();
					window.location.reload();
				});
			});
		}
		function toSet(id) {
			var url = "${BASE_PATH}/spike/list/toSet";
			var form = $("<form method='post'>");
			form.attr({
				"action" : url
			});
			/* for(arg in id){ */
			var input = $("<input type='hidden'>");
			input.attr({
				"name" : "listid"
			});
			input.val(id);
			form.append(input);
			/* } */
			$("html").append(form);
			form.submit();
		}
		var editDialog;
		function toEdit(id) {
			editDialog = Kit.dialog("编辑",
					"${BASE_PATH}/spike/list/toEdit/"+id).open();
		}
		function onEditSuccess(id, newObject) {
			$("#item" + id).replaceWith(template("list-tpl", {
				"list" : [ newObject ]
			}));
		}
	</script>
</body>
</html>